﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BridgeShips
{
    public class ShipsPositionValuesDate : UDPDateBase
    {
        private int m_ShipID;
        private uint m_ShipHashID;
        private bool m_isFirst;
        private Vector3 m_IDToUnityPosition;
        private List<string> m_str = new List<string>();
        public override void GetDictionaryDate(string date)
        {
            m_str.Clear();
            m_str = SpitReceivedMsgs.SpitMsgs(date);
            SaveMassages();
        }
        void SaveMassages() {
            m_ShipID = int.Parse(m_str[1]);
            //if (m_ShipID > 2)
            //    return;
            if (m_ShipID % 2 == 0)
            {
                m_ShipHashID= ShipsDictionary.Instance.HashCode((uint)(m_ShipID - 1), (uint)(m_ShipID));
                m_isFirst = false;
            }
            else
            {
                m_ShipHashID = ShipsDictionary.Instance.HashCode((uint)m_ShipID, (uint)(m_ShipID + 1));
                m_isFirst = true;
            }
          
            if (ShipsDictionary.Instance.IsExistID(m_ShipHashID))
            {
                //经纬度坐标转换成世界坐标
                //if(m_ShipHashID == 102)
                //{
                //    m_IDToUnityPosition = new Vector3(1050.9f,7.0f, 959.1f);
                //}
                //else if(m_ShipHashID == 304)
                //{
                //    m_IDToUnityPosition =new Vector3(1054.241f, 7.0f, 920.751f);


                //}
                //else 
                    m_IDToUnityPosition = ShipsDictionary.Instance.ConvertToUnityPosition(m_str[2], m_str[3]);
                if (Mathf.Abs(m_IDToUnityPosition.x) > 4000 || Mathf.Abs(m_IDToUnityPosition.z) > 4000)
                    return;
                ShipsDictionary.Instance.ChangeShipDicValues(m_ShipHashID, m_IDToUnityPosition, m_isFirst);
            }
        }
    }
}